package com.tanhua.manager;

import com.tanhua.domain.FreeZing;
import com.tanhua.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/manage")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping(name = "用户登出", value = "/users/{userID}")
    public ResponseEntity findByUid(@PathVariable("userID") Long userId) throws Exception {

        return userService.findByUid(userId);
    }


    @GetMapping(name = "用户信息的分页查询展示", value = "/users")
    public ResponseEntity users(Integer page, Integer pagesize) throws Exception {
        return userService.findUsers(page, pagesize);
    }


    @GetMapping(name = "分页展示用户的小视频", value = "/videos")
    public ResponseEntity findByvideos(Integer page, Integer pagesize, Long uid) throws Exception {

        return userService.findByvideos(page, pagesize, uid);
    }


    @GetMapping(name = "分页展示用户的动态或审核状态的动态", value = "/messages")
    public ResponseEntity messages(Integer page, Integer pagesize, Long uid, Integer state) throws Exception {

        return userService.messages(page, pagesize, uid, state);
    }


    @GetMapping(name = "单条动态详情展示", value = "/messages/{id}")
    public ResponseEntity findByPublishId(@PathVariable("id") String id) throws Exception {

        return userService.findByPublishId(id);
    }


    @GetMapping(name = "单条动态详情展示", value = "/messages/comments")
    public ResponseEntity findByComments(Integer page, Integer pagesize, String messageID) throws Exception {

        return userService.findByComments(page, pagesize, messageID);
    }

    @PostMapping(name = "冻结用户", value = "/users/freeze")
    public ResponseEntity freeze(@RequestBody FreeZing freeZing) {

        return userService.freezeUser(freeZing);
    }

    @PostMapping(name = "用户解冻操作", value = "/users/unfreeze")
    public ResponseEntity freeze(@RequestBody Map<String, String> map) {
        String userId = map.get("userId");
        return userService.unfreezeUser(userId);
    }


    @PostMapping(name = "动态通过", value = "/messages/pass")
    public ResponseEntity publishPass(@RequestBody List<String> map) {
        return userService.publishPass(map);
    }
}
